package com.spi.config;

import com.spi.xxjob.executer1.JobHandler;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;

import java.util.logging.Logger;

//@Configuration
@ComponentScan(basePackages = {"com.spi.xxjob.executer1"},
        excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com\\.spi\\.xxjob\\.executer2\\..*"))

public class XxlJobConfig {

    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    @Value("${xxl.job.executor1.appname}")
    private String appname1;

    @Value("${xxl.job.executor1.ip}")
    private String ip1;

    @Value("${xxl.job.executor1.port}")
    private int port1;

    @Value("${xxl.job.executor1.logpath}")
    private String logPath1;

    @Value("${xxl.job.executor1.logretentiondays}")
    private int logRetentionDays1;

    @Value("${xxl.job.executor1.accessToken}")
    private String accessToken1;

    @Autowired
    private JobHandler jobHandler ;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        //logger.info(">>>>>>>>>>> xxl-job config init for executor1.");
        System.out.println("执行器1初始化完毕");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appname1);
        xxlJobSpringExecutor.setIp(ip1);
        xxlJobSpringExecutor.setPort(port1);
        xxlJobSpringExecutor.setLogPath(logPath1);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays1);
        xxlJobSpringExecutor.setAccessToken(accessToken1);
        // 手动注册 JobHandle
        //xxlJobSpringExecutor.registerJobHandler("myjobhandler_test1", jobHandler);

        return xxlJobSpringExecutor;
    }


}
